﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{

    class ISYC_306_04
    {
        //图F.62  ISYC 306-04-可转位刀片扩孔、平底锪钻
        public static void ISYC_306_04_g(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]);
            // double sl_ = 45;
            // double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dc = 20 * scale;
            double df = 22 * scale;
            double lu = 45 * scale;
            double dcintf = 5 * scale;
            double dconms = 21 * scale;
            double lcf = 40 * scale;
            double ls = 50 * scale;
            double oal = 100*scale ;
            double sig = 180;
            double sig_ = sig * pi / 180;
            double pl = ((dc / 2.0 - dcintf / 2.0) / 2.0) / Math.Tan(sig_ / 2);
            double lta = oal - pl;
            */
              double dc = Convert.ToDouble(data["dc"]) * scale;
            double df = Convert.ToDouble(data["df"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double dcintf = Convert.ToDouble(data["dcintf"]) * scale;
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double lcf = Convert.ToDouble(data["lcf"]) * scale;
            double oal= Convert.ToDouble(data["oal"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double sig = Convert.ToDouble(data["sig"]);
            double sig_ = sig * pi / 180;
            double pl = ((dc / 2.0 - dcintf / 2.0) / 2.0) / Math.Tan(sig_ / 2);
            double lta = oal - pl;
            
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //切削部分
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0, 0, oal + 5);
            Vector2 p1 = fun.Polar(p0, sig_ /2, dcintf / 2.0);
            Vector2 p2 = fun.Polar(p1, sig_ /2, (dc - dcintf) / 2.0);
            Vector2 p3 = fun.Polar(p2, fun.CalAngle(p2, p1) + pi / 2, fun.CalDistance(p2, p1));
            Vector2 p4 = fun.Polar(p3, fun.CalAngle(p3, p2) +pi / 2, fun.CalDistance(p2, p1));
            Vector2 p5 = fun.mirrorpoint(p1, p0_1, p0_2);
            Vector2 p6 = fun.mirrorpoint(p2, p0_1, p0_2);
            Vector2 p7 = fun.mirrorpoint(p3, p0_1, p0_2);
            Vector2 p8 = fun.Polar(p0, 0, fun.CalDistance(p1, p4) / 5.0);
            Vector2 p9_0 = fun.Polar(p8, pi / 2, oal);
            Vector2 p9 = fun.Inters(p8, p9_0, p1, p4);
            Vector2 p10 = fun.Polar(p7, pi / 2, p8.X);
            Vector2 p11_1 = fun.Polar(p10, pi, oal);
            Vector2 p11_2 = fun.Polar(p8, pi / -2, oal);
            Vector2 p11 = fun.Inters(p10, p11_1, p8, p11_2);
            Vector2 p12_0 = fun.Polar(p5, 0, oal);
            Vector2 p12 = fun.Inters(p5, p12_0, p8, p11);
            Vector2 p13 = fun.Polar(p3, pi / -2, fun.CalDistance(p1, p9));
            Vector2 p14 = new Vector2(oal - ls, 0);
            Vector2 p15 = fun.Polar(p14, pi / 2, df / 2.0);
            Vector2 p16 = fun.Polar(p15, pi, (oal - ls) * (5.25 / 125.4));
            Vector2 p17 = fun.Polar(p16, pi + pi / 4, Math.Sqrt(2) * (p16.Y - p13.Y));
            Vector2 p18 = new Vector2(lcf, p17.Y);
            Vector2 p19 = fun.mirrorpoint(p15, p0_1, p0_2);
            Vector2 p20 = fun.mirrorpoint(p16, p0_1, p0_2);
            Vector2 p21 = fun.mirrorpoint(p17, p0_1, p0_2);
            Vector2 p22 = fun.mirrorpoint(p18, p0_1, p0_2);
            Vector2 p23 = fun.Polar(p8, pi / 2, fun.CalDistance(p8, p9) / 2.0);
            Vector2 p24 = fun.Inters(p2, p4, p1, p3);
            Vector2 p25_1 = fun.Polar(p17, pi / -2,p16.Y -p17.Y  );
            Vector2 p25_2 = fun.Polar(p25_1, 0, ls);
            Vector2 p25 = fun.Inters(p25_1, p25_2, p16, p20);
            Vector2 p26 = fun.Inters(p25_1, p25_2, p15, p19);
            Vector2 p27 = fun.mirrorpoint(p25, p0_1, p0_2);
            Vector2 p28 = fun.mirrorpoint(p26, p0_1, p0_2);
            Vector2 p29 = new Vector2(p18.X / 2.0, p23.Y);
            Vector2 arc2_1 = fun.Polar(p29, pi / -2, 0.01 * scale);
            Vector2 arc2_2 = fun.Polar(arc2_1, 0, ls);
            Vector2 arc1_1 = fun.Polar(p17, 0, 0.1);
            Vector2 arc1_2 = new Vector2(arc1_1.X , -ls);
            Vector2 p30 = new Vector2(oal, 0);
            Vector2 p31 = fun.Polar(p30, pi / 2, (dconms/2.0) - ((dconms / 2.0) / 10.0));
            Vector2 p32 = fun.Polar(p31, pi - pi / 4, Math.Sqrt(2) * ((dconms / 2.0) / 10.0));
            Vector2 p33 = fun.Polar(p32, pi, ls - (dconms / 2.0) / 10.0 - (dconms / 2.0) / 10.0 * 3);
            Vector2 p34 = fun.Polar(p33, pi / -2, (dconms/2.0) / 10.0);
            Vector2 p35 = fun.Polar(p34, pi, (dconms / 2.0) / 10.0 * 3);
            Vector2 p36 = fun.mirrorpoint(p31, p0_1, p0_2);
            Vector2 p37 = fun.mirrorpoint(p32, p0_1, p0_2);
            Vector2 p38 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p39 = fun.mirrorpoint(p34, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p35, p0_1, p0_2);
            //刨面
            Vector2 p49 = fun.Polar(p0, pi, dconms * 2);
            Vector2 p50 = fun.Polar(p49, pi / 2, dc / 2.0);
            Vector2 p51 = fun.Polar(p50, pi / 2, dc / 4.0);
            Vector2 p52 = fun.Polar(p51, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p53 = fun.Polar(p52, -10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p54 = fun.Polar(p53, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p55 = fun.Polar(p54, -10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p56 = fun.Polar(p55, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p57 = fun.Polar(p56, pi / -2, fun.CalDistance(p50, p51));
            Vector2 p58 = fun.mirrorpoint(p50, p0_1, p0_2);
            Vector2 p59 = fun.mirrorpoint(p51, p0_1, p0_2);
            Vector2 p60 = fun.mirrorpoint(p52, p0_1, p0_2);
            Vector2 p61 = fun.mirrorpoint(p53, p0_1, p0_2);
            Vector2 p62 = fun.mirrorpoint(p54, p0_1, p0_2);
            Vector2 p63 = fun.mirrorpoint(p55, p0_1, p0_2);
            Vector2 p64 = fun.mirrorpoint(p56, p0_1, p0_2);
            Vector2 p65 = fun.mirrorpoint(p57, p0_1, p0_2);
            var polyline4 = Pus.AddPointsToLwPolyLine(p50, p51, p52, p53, p54, p55, p56, p57, p50);
            var polyline5 = Pus.AddPointsToLwPolyLine(p58, p59, p60, p61, p62, p63, p64, p65, p58);
            for (double n = 1; n < 3; n++)
            {
                String[] htypen = new String[100];
                Line[] hlinen = new Line[100];
                Arc[] harcn = new Arc[100];
                var polylinen = polyline4;
                if (n == 1)
                {
                    polylinen = polyline4;
                }
                else
                {
                    polylinen = polyline5;
                }
                int hnumstn = polylinen.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumstn; i++)
                {
                    htypen[i] = polylinen.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htypen[i] == "Line")
                    {
                        hlinen[i] = (Line)polylinen.Explode()[i];
                    }
                    if (htypen[i] == "Arc")
                    {
                        harcn[i] = (Arc)polylinen.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htypen, hnumstn, 135, 10 * scale, hlinen, harcn, hatching);
            }
            fun.dimrot1(dxf, p50, p58, -90, dc / 10.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "PHD", "", "");
            //
            Arc arc1 = fun.DrawArc5(p25, new Line(arc1_1 ,arc1_2), p27);
            Arc arc2 = fun.DrawArc5(p29, new Line(arc2_1, arc2_2), p18);
            var polyline1 = Pus.AddPointsToLwPolyLine(p13, p3, p2, p1, p4, p13, p17, p16, p15, p26, p25,
            p16, p15, p26, p28, p27, p20, p19, p28, p27, p20, p21, p10, p7, p6, p5, p12, p11, p10, p11,p23,p29,p23, p9);
            var polyline2 = Pus.AddPointsToLwPolyLine(p35, p34, p39, p33, p32, p37, p32, p31, p36, p37, p38, p39, p40);
            polyline1.Vertexes[6].Bulge = Math.Tan((pi/2) / 4);
            polyline1.Vertexes[20].Bulge = Math.Tan((pi/2) / 4);
          /*  dxf.AddEntity(new EntityObject[] { polyline1 ,polyline2 ,polyline4 ,polyline5 
            ,arc1 ,arc2
            });*/
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            //非切削部分
            //标注
            /* fun.dimrot1(dxf, p1, p18, 90, dc, 2, 2 * scale, 2.4 * scale, 0.9, "DCB", "", "");
      fun.jdbz2(dxf, new Line(p4, p5), new Line(p7, p8), dc, 2 * scale, 2.4 * scale, 0.9, "SIG", "", "");
      fun.Axis(dxf, fun.Polar(p0, pi + pi / 3, dc * 2), 180, -90, "Z", "X", "Y", 1 * scale, 2 * scale, 0);
      fun.Axis(dxf, p0, 180, -90, "", "", "", 1 * scale, 2 * scale, 0);
      fun.Axis(dxf, p19, 180, -90, "", "", "", 1 * scale, 2 * scale, 0);
      fun.Singlelinearrow(dxf, "CCMS", v1, 110, fun.Polar(v1, 110 * pi / 180, dc / 2.0), fun.Polar(v1, 110 * pi / 180, dc), 1.2 * scale, 1.6 * scale);
      Text txt1 = new Text("PCS", v18, 2.2 *scale , 0);
      Circle circle1 = new Circle(p0, 1.7 * 2 * scale) ;
            */
            Vector2 v1 = fun.Polar(p18, pi, fun.CalDistance(p18, p17));//LU
            Vector2 v2 = fun.Polar(p33, 0, ls / 6.0);
            Vector2 v3 = fun.Polar(p0, pi - pi / 4, dc * 2);
            Vector2 v4 = fun.Polar(p2, pi - 70 * pi / 180, 0.5 * 1.7 * scale);
            Vector2 v5 = fun.Polar(p0, pi - pi / 3, 0.5 * 1.7 * scale);
            Vector2 v6 = fun.Polar(p14, pi / -4, 0.5 * 1.7 * scale);
            Vector2 v7 = fun.Polar(v6, pi / -4, dconms);
            fun.dimrot1(dxf, p2, v1 , 0, dc-(p2.Y -v1.Y )/2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p2, p18, 0, dc*1.5-(p2.Y -p18.Y )/2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LCF", "", "");
            fun.dimrot1(dxf, p2, p15 ,0, dc*2-(p15.Y -p2.Y )/2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LPR,LTA,LF", "", "");
            fun.dimrot1(dxf, p2, p31 ,0, dc*2.5-(p31.Y -p2.Y )/2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p2, p6 , 90, dc, 2, 1.2 * scale, 1.6 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p32, p37, -90, dc, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, p19 , p36 , 180, dc, 2, 1.2 * scale, 1.6 * scale, 0.9, "LS", "", "");
            fun.dimrot1(dxf, p1 , p5 , 90, dc/2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCINTF", "", "");
            fun.dimrot1(dxf, p16 , p20 , 90, dc/5.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DF", "", "");
            fun.jdbz2(dxf, new Line(p5, p6), new Line(p1, fun.Polar(p1, sig_ / 2.0 - 0.001 * pi / 180, 0.1)), dc, 1.2 * scale, 1.6 * scale, 0.9, "SIG", "", "") ;
            fun.Axis(dxf, fun.Polar(p30, -70*pi/180, dc *1.2), 0, -90, "Z", "X", "Y", 0.5 * scale, 1.2 * scale, 0);
            fun.Axis(dxf, p14, 180, -90, "", "", "", 0.5 * scale, 1.2 * scale, 0);
            fun.Axis(dxf, p0, 180, -90, "", "", "", 0.5 * scale, 1.2 * scale, 0);
            fun.Singlelinearrow(dxf, "CCMS", v2, 60, fun.Polar(v2, pi/3, dc / 2.0), fun.Polar(v2, pi/3, dc), 1.2 * scale, 1.6 * scale);
            fun.Singlelinearrow(dxf, "FDP", v3, 180, fun.Polar(v3, 0, dc / 2.0), fun.Polar(v3, 0, dc), 1.2 * scale, 1.6 * scale);
            Line linev1 = new Line(v4, fun.Polar(v4, pi - 70 * pi / 180, dc / 2.0));
            Line linev2 = new Line(v5, fun.Polar(v5, pi - pi/ 3, dc / 1.5));
            Line linev3 = new Line(v6, v7);
            Line linev4 = new Line(p0_1 , p0_2 );
            linev4.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev4.Layer = centre  ;//Layer指图层
            linev4.LinetypeScale = 5 * scale ;//指线性比例
            linev4.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev4); //提取
            Text txt1 = new Text("CRP", fun.Polar(v4, pi-70 * pi / 180, dc / 2.0), 1.2 * scale, 0);
            Text txt2 = new Text("CIP", fun.Polar(v5, pi-pi / 3, dc / 1.5), 1.2 * scale, 0);
            Text txt3 = new Text("PCS,MCS", fun.Polar(v7, pi / -2, 1.2*scale ), 1.2 * scale, 0);
            Text txt4 = new Text("ISYC=306_04", fun.Polar(p16 , pi / 2, dc *3), 1.2 * scale, 0);

            Circle circle1 = new Circle(p2, 1.7 * 0.5 * scale);
            Circle circle2 = new Circle(p0 , 1.7 * 0.5 * scale);
            Circle circle3 = new Circle(p14, 1.7 * 0.5 * scale);

            dxf.AddEntity(new EntityObject[] {linev1,linev2 ,linev3 
            ,txt1,txt2 ,txt3 ,txt4 
            ,circle1,circle2 ,circle3 
            });

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void ISYC_306_04_j(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]);
           //  double sl_ = 45;
           //  double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dc = 20 * scale;
            double df = 22 * scale;
            double lu = 45 * scale;
            double dcintf = 5 * scale;
            double dconms = 21 * scale;
            double lcf = 40 * scale;
            double ls = 50 * scale;
            double oal = 100*scale ;
            double sig = 180;
            double sig_ = sig * pi / 180;
            double pl = ((dc / 2.0 - dcintf / 2.0) / 2.0) / Math.Tan(sig_ / 2);
            double lta = oal - pl;
            */
            double dc = Convert.ToDouble(data["dc"]) * scale;
            double df = Convert.ToDouble(data["df"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double dcintf = Convert.ToDouble(data["dcintf"]) * scale;
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double lcf = Convert.ToDouble(data["lcf"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double sig = Convert.ToDouble(data["sig"]);
            double sig_ = sig * pi / 180;
            double pl = ((dc / 2.0 - dcintf / 2.0) / 2.0) / Math.Tan(sig_ / 2);
            double lta = oal - pl;
            
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //切削部分
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0, 0, oal + 5);
            Vector2 p1 = fun.Polar(p0, sig_ / 2, dcintf / 2.0);
            Vector2 p2 = fun.Polar(p1, sig_ / 2, (dc - dcintf) / 2.0);
            Vector2 p3 = fun.Polar(p2, fun.CalAngle(p2, p1) + pi / 2, fun.CalDistance(p2, p1));
            Vector2 p4 = fun.Polar(p3, fun.CalAngle(p3, p2) + pi / 2, fun.CalDistance(p2, p1));
            Vector2 p5 = fun.mirrorpoint(p1, p0_1, p0_2);
            Vector2 p6 = fun.mirrorpoint(p2, p0_1, p0_2);
            Vector2 p7 = fun.mirrorpoint(p3, p0_1, p0_2);
            Vector2 p8 = fun.Polar(p0, 0, fun.CalDistance(p1, p4) / 5.0);
            Vector2 p9_0 = fun.Polar(p8, pi / 2, oal);
            Vector2 p9 = fun.Inters(p8, p9_0, p1, p4);
            Vector2 p10 = fun.Polar(p7, pi / 2, p8.X);
            Vector2 p11_1 = fun.Polar(p10, pi, oal);
            Vector2 p11_2 = fun.Polar(p8, pi / -2, oal);
            Vector2 p11 = fun.Inters(p10, p11_1, p8, p11_2);
            Vector2 p12_0 = fun.Polar(p5, 0, oal);
            Vector2 p12 = fun.Inters(p5, p12_0, p8, p11);
            Vector2 p13 = fun.Polar(p3, pi / -2, fun.CalDistance(p1, p9));
            Vector2 p14 = new Vector2(oal - ls, 0);
            Vector2 p15 = fun.Polar(p14, pi / 2, df / 2.0);
            Vector2 p16 = fun.Polar(p15, pi, (oal - ls) * (5.25 / 125.4));
            Vector2 p17 = fun.Polar(p16, pi + pi / 4, Math.Sqrt(2) * (p16.Y - p13.Y));
            Vector2 p18 = new Vector2(lcf, p17.Y);
            Vector2 p19 = fun.mirrorpoint(p15, p0_1, p0_2);
            Vector2 p20 = fun.mirrorpoint(p16, p0_1, p0_2);
            Vector2 p21 = fun.mirrorpoint(p17, p0_1, p0_2);
            Vector2 p22 = fun.mirrorpoint(p18, p0_1, p0_2);
            Vector2 p23 = fun.Polar(p8, pi / 2, fun.CalDistance(p8, p9) / 2.0);
            Vector2 p24 = fun.Inters(p2, p4, p1, p3);
            Vector2 p25_1 = fun.Polar(p17, pi / -2, p16.Y - p17.Y);
            Vector2 p25_2 = fun.Polar(p25_1, 0, ls);
            Vector2 p25 = fun.Inters(p25_1, p25_2, p16, p20);
            Vector2 p26 = fun.Inters(p25_1, p25_2, p15, p19);
            Vector2 p27 = fun.mirrorpoint(p25, p0_1, p0_2);
            Vector2 p28 = fun.mirrorpoint(p26, p0_1, p0_2);
            Vector2 p29 = new Vector2(p18.X / 2.0, p23.Y);
            Vector2 arc2_1 = fun.Polar(p29, pi / -2, 0.01 * scale);
            Vector2 arc2_2 = fun.Polar(arc2_1, 0, ls);
            Vector2 arc1_1 = fun.Polar(p17, 0, 0.1);
            Vector2 arc1_2 = new Vector2(arc1_1.X, -ls);
            Vector2 p30 = new Vector2(oal, 0);
            Vector2 p31 = fun.Polar(p30, pi / 2, (dconms / 2.0) - ((dconms / 2.0) / 10.0));
            Vector2 p32 = fun.Polar(p31, pi - pi / 4, Math.Sqrt(2) * ((dconms / 2.0) / 10.0));
            Vector2 p33 = fun.Polar(p32, pi, ls - (dconms / 2.0) / 10.0 - (dconms / 2.0) / 10.0 * 3);
            Vector2 p34 = fun.Polar(p33, pi / -2, (dconms / 2.0) / 10.0);
            Vector2 p35 = fun.Polar(p34, pi, (dconms / 2.0) / 10.0 * 3);
            Vector2 p36 = fun.mirrorpoint(p31, p0_1, p0_2);
            Vector2 p37 = fun.mirrorpoint(p32, p0_1, p0_2);
            Vector2 p38 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p39 = fun.mirrorpoint(p34, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p35, p0_1, p0_2);
            //刨面
            Vector2 p49 = fun.Polar(p0, pi, dconms * 2);
            Vector2 p50 = fun.Polar(p49, pi / 2, dc / 2.0);
            Vector2 p51 = fun.Polar(p50, pi / 2, dc / 4.0);
            Vector2 p52 = fun.Polar(p51, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p53 = fun.Polar(p52, -10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p54 = fun.Polar(p53, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p55 = fun.Polar(p54, -10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p56 = fun.Polar(p55, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p57 = fun.Polar(p56, pi / -2, fun.CalDistance(p50, p51));
            Vector2 p58 = fun.mirrorpoint(p50, p0_1, p0_2);
            Vector2 p59 = fun.mirrorpoint(p51, p0_1, p0_2);
            Vector2 p60 = fun.mirrorpoint(p52, p0_1, p0_2);
            Vector2 p61 = fun.mirrorpoint(p53, p0_1, p0_2);
            Vector2 p62 = fun.mirrorpoint(p54, p0_1, p0_2);
            Vector2 p63 = fun.mirrorpoint(p55, p0_1, p0_2);
            Vector2 p64 = fun.mirrorpoint(p56, p0_1, p0_2);
            Vector2 p65 = fun.mirrorpoint(p57, p0_1, p0_2);
            var polyline4 = Pus.AddPointsToLwPolyLine(p50, p51, p52, p53, p54, p55, p56, p57, p50);
            var polyline5 = Pus.AddPointsToLwPolyLine(p58, p59, p60, p61, p62, p63, p64, p65, p58);
            for (double n = 1; n < 3; n++)
            {
                String[] htypen = new String[100];
                Line[] hlinen = new Line[100];
                Arc[] harcn = new Arc[100];
                var polylinen = polyline4;
                if (n == 1)
                {
                    polylinen = polyline4;
                }
                else
                {
                    polylinen = polyline5;
                }
                int hnumstn = polylinen.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumstn; i++)
                {
                    htypen[i] = polylinen.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htypen[i] == "Line")
                    {
                        hlinen[i] = (Line)polylinen.Explode()[i];
                    }
                    if (htypen[i] == "Arc")
                    {
                        harcn[i] = (Arc)polylinen.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htypen, hnumstn, 135, 10 * scale, hlinen, harcn, hatching);
            }
            fun.dimrot1(dxf, p50, p58, -90, dc / 10.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "PHD", "", "");
            //
            Arc arc1 = fun.DrawArc5(p25, new Line(arc1_1, arc1_2), p27);
            Arc arc2 = fun.DrawArc5(p29, new Line(arc2_1, arc2_2), p18);
            var polyline1 = Pus.AddPointsToLwPolyLine(p13, p3, p2, p1, p4, p13, p17, p16, p15, p26, p25,
            p16, p15, p26, p28, p27, p20, p19, p28, p27, p20, p21, p10, p7, p6, p5, p12, p11, p10, p11, p23, p29, p23, p9);
            var polyline2 = Pus.AddPointsToLwPolyLine(p35, p34, p39, p33, p32, p37, p32, p31, p36, p37, p38, p39, p40);
            var polyline6 = Pus.AddPointsToLwPolyLine(p26,p27,p25,p28);
           polyline1.Vertexes[6].Bulge = Math.Tan((pi / 2) / 4);
            polyline1.Vertexes[20].Bulge = Math.Tan((pi / 2) / 4);
            /*  dxf.AddEntity(new EntityObject[] { polyline1 ,polyline2 ,polyline4 ,polyline5 
              ,arc1 ,arc2
              });*/
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            fun.PolyFill(dxf, polyline6, 0.5, contour);
            //fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            Line linev4 = new Line(p0_1, p0_2);
            linev4.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev4.Layer = centre;//Layer指图层
            linev4.LinetypeScale = 5 * scale;//指线性比例
            linev4.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev4); //提取
                                   //非切削部分

            Vector2 v1 = fun.Polar(p18, pi, fun.CalDistance(p18, p17));//LU
            Vector2 v2 = fun.Polar(p33, 0, ls / 6.0);
            Vector2 v3 = fun.Polar(p0, pi - pi / 4, dc * 2);
            Vector2 v4 = fun.Polar(p2, pi - 70 * pi / 180, 0.5 * 1.7 * scale);
            Vector2 v5 = fun.Polar(p0, pi - pi / 3, 0.5 * 1.7 * scale);
            Vector2 v6 = fun.Polar(p14, pi / -4, 0.5 * 1.7 * scale);
            Vector2 v7 = fun.Polar(v6, pi / -4, dconms);
            fun.dimrot1(dxf, p2, v1, 0, dc - (p2.Y - v1.Y) / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p2, p18, 0, dc * 1.5 - (p2.Y - p18.Y) / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LCF", "", "");
            fun.dimrot1(dxf, p2, p15, 0, dc * 2 - (p15.Y - p2.Y) / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, p2, p31, 0, dc * 2.5 - (p31.Y - p2.Y) / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p2, p6, 90, dc, 2, 1.2 * scale, 1.6 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p32, p37, -90, dc, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, p19, p36, 180, dc, 2, 1.2 * scale, 1.6 * scale, 0.9, "LS", "", "");
            //fun.dimrot1(dxf, p1, p5, 90, dc / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCINTF", "", "");
            //fun.dimrot1(dxf, p16, p20, 90, dc / 5.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DF", "", "");
            fun.jdbz2(dxf, new Line(p5, p6), new Line(p1, fun.Polar(p1, sig_ / 2.0 - 0.001 * pi / 180, 0.1)), dc, 1.2 * scale, 1.6 * scale, 0.9, "SIG="+180+"°", "", "");
            /* fun.Axis(dxf, fun.Polar(p30, -70 * pi / 180, dc * 1.2), 0, -90, "Z", "X", "Y", 0.5 * scale, 1.2 * scale, 0);
             fun.Axis(dxf, p14, 180, -90, "", "", "", 0.5 * scale, 1.2 * scale, 0);
             fun.Axis(dxf, p0, 180, -90, "", "", "", 0.5 * scale, 1.2 * scale, 0);
             fun.Singlelinearrow(dxf, "CCMS", v2, 60, fun.Polar(v2, pi / 3, dc / 2.0), fun.Polar(v2, pi / 3, dc), 1.2 * scale, 1.6 * scale);
             fun.Singlelinearrow(dxf, "FDP", v3, 180, fun.Polar(v3, 0, dc / 2.0), fun.Polar(v3, 0, dc), 1.2 * scale, 1.6 * scale);
             Line linev1 = new Line(v4, fun.Polar(v4, pi - 70 * pi / 180, dc / 2.0));
             Line linev2 = new Line(v5, fun.Polar(v5, pi - pi / 3, dc / 1.5));
             Line linev3 = new Line(v6, v7);

             Text txt1 = new Text("CRP", fun.Polar(v4, pi - 70 * pi / 180, dc / 2.0), 1.2 * scale, 0);
             Text txt2 = new Text("CIP", fun.Polar(v5, pi - pi / 3, dc / 1.5), 1.2 * scale, 0);
             Text txt3 = new Text("PCS,MCS", fun.Polar(v7, pi / -2, 1.2 * scale), 1.2 * scale, 0);
             Text txt4 = new Text("ISYC=306_04", fun.Polar(p16, pi / 2, dc * 3), 1.2 * scale, 0);

             Circle circle1 = new Circle(p2, 1.7 * 0.5 * scale);
             Circle circle2 = new Circle(p0, 1.7 * 0.5 * scale);
             Circle circle3 = new Circle(p14, 1.7 * 0.5 * scale);

             dxf.AddEntity(new EntityObject[] {linev1,linev2 ,linev3
             ,txt1,txt2 ,txt3 ,txt4
             ,circle1,circle2 ,circle3
             });*/

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}